package cn.group.service.impl;

import cn.group.dao.RoomDao;
import cn.group.domain.Room;
import cn.group.service.RoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService{
    private RoomDao roomDao;
    @Autowired
    public RoomServiceImpl(RoomDao roomDao){
        this.roomDao = roomDao;
    }
    @Override
    public List<Room> getAll() {
        return roomDao.queryAll();
    }

    @Override
    public PageInfo<Room> getRoomByPage(Integer currentPage, Integer pagesize) {
        //pagehelper内部计算总共有多少页
        PageHelper.startPage(currentPage,pagesize);
        List<Room>roomList = roomDao.queryAll();
        PageInfo<Room>pageInfo = new PageInfo<>(roomList);
        return pageInfo;
    }

    @Override
    public boolean addOne(Room room) {
        int result = roomDao.insertOne(room);
        return result>0;
    }

    @Override
    public boolean modifyOne(Room room) {
        int result = roomDao.updateByRoom(room);
        return result>0;
    }

    @Override
    public boolean removeOne(Integer id) {
        int result = roomDao.deteleByRoom(id);
        return result>0;
    }

    @Override
    public Room getOneById(Integer id) {
        Room room = roomDao.queryOneById(id);
        return room;
    }


}
